package com.yj.event_listener.util;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CallLog;

import com.yj.event_listener.contentObserver.CalendarContentObserver;

public class CalendarUtil {

    public static Cursor getCalendarAlertContent(Context context, long current) {
        // Define the content URI for calendar alerts
        Uri uri = CalendarContract.CalendarAlerts.CONTENT_URI;

        // Define the projection (columns to retrieve)
        String[] projection = {
                CalendarContract.CalendarAlerts._ID,
                CalendarContract.CalendarAlerts.TITLE,
                CalendarContract.CalendarAlerts.EVENT_LOCATION,
                CalendarContract.CalendarAlerts.ALARM_TIME,
                CalendarContract.CalendarAlerts.DESCRIPTION,
                CalendarContract.CalendarAlerts.AVAILABILITY,
                CalendarContract.CalendarAlerts.STATUS,
                CalendarContract.CalendarAlerts.STATE,
                CalendarContract.CalendarAlerts.HAS_ALARM,
                CalendarContract.CalendarAlerts.BEGIN
        };

        long time = (current / 1000) * 1000;
        LogUtil.d("alerm time " + time);

        // Perform the query
        ContentResolver contentResolver = context.getContentResolver();
        Bundle bundle = new Bundle();
        bundle.putString(ContentResolver.QUERY_ARG_SQL_SELECTION,
//                CalendarContract.CalendarAlerts.STATE + " == ? AND " +
                CalendarContract.CalendarAlerts.ALARM_TIME + " == ? "
                );
        bundle.putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS,
                new String[]{
//                        String.valueOf(CalendarContract.CalendarAlerts.STATE_FIRED),
                        String.valueOf(time)
                }
        );

        return contentResolver.query(uri, projection, bundle, null);
    }


}
